﻿Imports System.Data
Partial Class Egresados_Ofertas_Ofertas
    Inherits PaginaComun

    Protected Sub ImageButton1_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles ImageButton1.Click
        Dim obj As New Ofertas
        obj.TITULO = TxtTitulo.Text
        obj.DESCRIPCION = TxtDesc.Text
        obj.TIPO_EMPLEO = CmbTipEmpleo.SelectedValue
        obj.DURACION = TxtDur.Text
        obj.SALARIO = TxtSal.Value
        obj.COMIENZO = TxtFecIni.Text
        obj.VACANTES = TxtVac.Value
        obj.TIP_CONVENIO = CmbConvenio.SelectedValue
        obj.IDPK = Me.Pk1
        Dim j As String = 0, prog As String
        Dim chk As New CheckBox, txt, txtfac As New TextBox
        For i = 0 To DataList1.Items.Count - 1
            chk = DataList1.Items(i).FindControl("chknomprog")
            txt = DataList1.Items(i).FindControl("txtcodprog")
            If chk.Checked = True Then
                If prog = "" Then
                    prog = txt.Text
                Else
                    prog += "," + txt.Text
                End If
            End If
        Next
        obj.PROG = prog
        Select Case Me.Oper
            Case "Nuevo"
                MsgModalPanel.Text = obj.Insert
                If obj.lErrorG = False Then
                    ImgRst.ImageUrl = "~/imagenes/good.png"
                Else
                    ImgRst.ImageUrl = "~/imagenes/error.png"
                End If
                ModalPopup.Show()
            Case "Editar"
                MsgModalPanel.Text = obj.Update
                If obj.lErrorG = False Then
                    ImgRst.ImageUrl = "~/imagenes/good.png"
                Else
                    ImgRst.ImageUrl = "~/imagenes/error.png"
                End If
                ModalPopup.Show()
        End Select
        Me.GridView1.DataBind()
        If obj.lErrorG = False Then
            Me.MultiView1.ActiveViewIndex = 1
        End If
    End Sub

    Sub limpiar()
        'TxtEmp.Text = ""
        'TxtJefe.Text = ""
        'DtpFecI.SelectedDate = Today
        'DtpFecR.SelectedDate = Today
        'TxtDur.Value = 0
    End Sub

    Protected Sub ImageButton2_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles ImageButton2.Click
        Me.MultiView1.ActiveViewIndex = 1
    End Sub

    Protected Sub GridView1_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles GridView1.RowCommand
        Dim obj As New Ofertas
        Select Case e.CommandName
            Case "Editar"
                Me.Oper = "Editar"
                Dim index As Integer = Convert.ToInt32(e.CommandArgument)
                GridView1.SelectedIndex = index
                Dim dt As DataTable = obj.GetbyPK(GridView1.DataKeys(index).Values(0).ToString())
                If dt.Rows.Count > 0 Then
                    Me.LbOper.Text = "EDITANDO OFERTA..."
                    Me.TxtTitulo.Text = dt.Rows(0)("Titulo").ToString
                    Me.TxtDesc.Text = dt.Rows(0)("Descripcion").ToString
                    Me.CmbTipEmpleo.SelectedValue = dt.Rows(0)("Tipo_Empleo").ToString
                    Me.TxtDur.Text = dt.Rows(0)("Duracion").ToString
                    Me.TxtSal.Text = dt.Rows(0)("Salario").ToString
                    Me.TxtFecIni.Text = CDate(dt.Rows(0)("Comienzo").ToString).ToShortDateString
                    Me.TxtVac.Text = dt.Rows(0)("Vacantes").ToString
                    Me.Pk1 = dt.Rows(0)("Id_Oferta").ToString
                    Me.HfPK.Value = dt.Rows(0)("Id_Oferta").ToString
                    Me.MultiView1.ActiveViewIndex = 0
                End If
            Case "Eliminar"
                Dim index As Integer = Convert.ToInt32(e.CommandArgument)
                GridView1.SelectedIndex = index
                Me.Pk1 = GridView1.DataKeys(index).Values(0).ToString()
                Me.ModalPopupExtender1.Show()
        End Select
    End Sub

    Protected Sub ImageButton3_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles ImageButton3.Click
        Me.Oper = "Nuevo"
        Me.LbOper.Text = "NUEVA OFERTA"
        limpiar()
        Me.MultiView1.ActiveViewIndex = 0
        Me.CmbConvenio.SelectedValue = "CA"
        Me.TxtSal.Value = CDec(Publico.Salario_Minimo) * 0.75
        Me.TxtSal.Enabled = False
    End Sub

    Protected Sub Button4_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button4.Click
        Dim obj As New Estudios
        MsgModalPanel.Text = obj.Delete(Me.Pk1)
        If obj.lErrorG = False Then
            ImgRst.ImageUrl = "~/imagenes/good.png"
        Else
            ImgRst.ImageUrl = "~/imagenes/error.png"
        End If
        ModalPopup.Show()
        GridView1.DataBind()
    End Sub

    'Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound
    '    If e.Row.RowType = DataControlRowType.DataRow Then
    '        Dim lbNFila As Label = CType(e.Row.FindControl("LbNumero"), Label)
    '        lbNFila.Text = ((e.Row.RowIndex + 1) + (GridView1.PageIndex * GridView1.PageSize)).ToString()
    '    End If
    'End Sub

    Protected Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles CmbConvenio.SelectedIndexChanged
        If CmbConvenio.SelectedValue = "CA" Then
            TxtSal.Value = CDec(Publico.Salario_Minimo) * 0.75
            TxtSal.Enabled = False
        Else
            TxtSal.Value = 0.0
            TxtSal.Enabled = True
        End If
    End Sub
End Class
